//
//  MSRegistSuccessViewController.m
//  SocietySale
//
//  Created by yumingwei on 2016/11/27.
//  Copyright © 2016年 Mike. All rights reserved.
//

#import "MSRegistSuccessViewController.h"
#import "MSRegistSuccessTableVC.h"
#import "MSInviteFriendsViewController.h"

@interface MSRegistSuccessViewController ()
@property (nonatomic, strong) MSRegistSuccessTableVC *tableVC;
@property (nonatomic, strong) UIView *footerView;
@end

@implementation MSRegistSuccessViewController

- (void)initUI{
    self.tableVC = [[MSRegistSuccessTableVC alloc] initWithStyle:UITableViewStyleGrouped];
    self.tableVC.view.frame = self.view.bounds;
    self.tableVC.enableRefresh = NO;
    self.tableVC.enableRequest = NO;
    self.tableVC.delegate = (id)self;
    self.tableVC.tableView.scrollEnabled = NO;
    self.tableVC.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableVC.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableVC.view];
    
    [self layoutHeaderView];
    [self layoutFooterView];
    
    UIButton *closeBtn = [[UIButton alloc] initWithFrame:CGRectMake(SCREEN_WIDTH-60, 20, 40, 40)];
    closeBtn.titleLabel.font = HeitiFont(15);
    [closeBtn setImage:[UIImage imageNamed:@"close"] forState:UIControlStateNormal];
    [closeBtn addTarget:self action:@selector(closeClick) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:closeBtn];
}

- (void)layoutHeaderView{
    UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 120)];
    headerView.backgroundColor = [UIColor whiteColor];
    self.tableVC.tableView.tableHeaderView = headerView;
    
    UILabel *label = [[UILabel alloc] init];
    label.frame = CGRectMake(0, 65, SCREEN_WIDTH, 30);
//    label.font = [];
    label.textColor = UIColorFromRGB(0xe8ab57);
    label.textAlignment = NSTextAlignmentCenter;
    [headerView addSubview:label];
    
    NSMutableAttributedString *titleAttstr = [[NSMutableAttributedString alloc] initWithString:@" 恭喜你注册成功！"];
    
    NSTextAttachment *textAttachment = [[NSTextAttachment alloc] initWithData:nil ofType:nil];
    textAttachment.bounds = CGRectMake(0, -5, 23, 23);
    textAttachment.image = [UIImage imageNamed:@"success"];
    NSAttributedString *attachmentString = [NSAttributedString attributedStringWithAttachment:textAttachment];
    [titleAttstr insertAttributedString:attachmentString atIndex:0];
    
    label.attributedText = titleAttstr;
}

- (void)layoutFooterView{
    _footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 230)];
    _footerView.backgroundColor = [UIColor whiteColor];
    self.tableVC.tableView.tableFooterView = _footerView;
    
    GXButton *shareBtn = [self creatBtnWithFrame:CGRectMake((SCREEN_WIDTH-44)/2, 0, 44, 70) andTitle:@"朋友圈"];
    shareBtn.tag = 10;
    shareBtn.relayout = YES;
    shareBtn.imageViewFrame = CGRectMake(0, 0, 44, 44);
    shareBtn.titleLabelFrame = CGRectMake(0, 48, 44, 20);
    [shareBtn setTitleColor:kDarkGrayColor forState:UIControlStateNormal];
    shareBtn.titleLabel.font = HeitiFont(12);
    [shareBtn setImage:[UIImage imageNamed:@"pengyouquan"] forState:UIControlStateNormal];

    GXButton *inviteBtn = [self creatBtnWithFrame:CGRectMake(70, shareBtn.bottom+20, SCREEN_WIDTH-140, 30) andTitle:@"邀请通讯录好友"];
    inviteBtn.tag = 20;
    inviteBtn.layer.cornerRadius = 2;
    inviteBtn.layer.borderWidth = 0.8;
    inviteBtn.layer.borderColor = kNormalGray.CGColor;
    [inviteBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [inviteBtn addTarget:self action:@selector(inviteClick) forControlEvents:UIControlEventTouchUpInside];
    inviteBtn.titleLabel.font = HeitiFont(13);
    
    GXButton *goInBtn = [self creatBtnWithFrame:CGRectMake(70, inviteBtn.bottom+60, SCREEN_WIDTH-140, 30) andTitle:@"直接进入首页》"];
    goInBtn.tag = 30;
    [goInBtn setTitleColor:kLightGrayColor forState:UIControlStateNormal];
    [goInBtn addTarget:self action:@selector(closeClick) forControlEvents:UIControlEventTouchUpInside];
    goInBtn.titleLabel.font = HeitiFont(12);
}

//创建btn
- (GXButton*)creatBtnWithFrame:(CGRect)frame andTitle:(NSString*)title{
    GXButton *btn = [GXButton buttonWithType:UIButtonTypeCustom];
    btn.frame = frame;
    btn.titleLabel.textAlignment = NSTextAlignmentCenter;
    [btn setTitle:title forState:UIControlStateNormal];
    [_footerView addSubview:btn];
    return btn;
}

- (void)testDataFunc{
    MSCommonModel *model = [[MSCommonModel alloc] init];
    model.title = @" 7天高级会员";
    model.subTitle = @" 所有功能免费使用，海量信息畅通无阻";
    model.thirdTitle = @"vstar-m";
    
    MSCommonModel *model2 = [[MSCommonModel alloc] init];
    model2.title = @" 20个江湖币";
    model2.subTitle = @" 江湖币可用来进行交易使用";
    model2.thirdTitle = @"coin";
    
    self.tableVC.dataArray = [@[model,model2] mutableCopy];
}

- (void)closeClick{
    [rootNavigation popToRootViewControllerAnimated:NO];
}

- (void)inviteClick{
    MSInviteFriendsViewController *vc = [[MSInviteFriendsViewController alloc] init];
    vc.isRegist = YES;
    [rootNavigation pushViewController:vc animated:YES];
}

@end
